import axios from "axios";
import service from "@/config/index";

const URLS = {
  RESOURCE: "/resource",
  SEARCH: "/resource/search",
  SAVE: "/menu/resource/save"
};

export default {
  search(filter = {}) {
    return axios.post(URLS.SEARCH, filter);
  },
  searchName(name) {
    return axios.get(`${service.serviceAdmin}/resource/name/${name}`);
  },
  submit(resource = {}) {
    let { resourceId } = resource;
    if (resourceId) {
      return axios.put(`${URLS.RESOURCE}/${resourceId}`, resource);
    } else {
      return axios.post(URLS.RESOURCE, resource);
    }
  },
  save(params) {
    return axios.post(URLS.SAVE, params);
  }
};
